//+------------------------------------------------------------------+ //| CCI.mq4 | //| not me | //| | //+------------------------------------------------------------------+ #property copyright "not me" #property link "" extern int longperiod; bool onswitch; int magic=1999; extern int shortperiod; bool offswitch; extern int takeprofit; extern int stoploss; extern int longema; extern int shortema; bool upswitch; bool upswitch2; bool downswitch; bool downswitch2; //+------------------------------------------------------------------+ //| expert initialization function | //+------------------------------------------------------------------+ int init() { //---- offswitch=true; onswitch=false; double ccilong=iCCI(Symbol(),0,longperiod,PRICE_OPEN,0); double ccishort=iCCI(Symbol(),0,shortperiod,PRICE_OPEN,0); if (ccishort > 0 && ccilong > 0) { upswitch=true; downswitch=false; } if (ccishort < 0 && ccilong < 0) { downswitch=true; upswitch=false; } //---- return(0); } //+------------------------------------------------------------------+ //| expert deinitialization function | //+------------------------------------------------------------------+ int deinit() { //---- //---- return(0); } //+------------------------------------------------------------------+ //| expert start function | //+------------------------------------------------------------------+ int start() { //---- RefreshRates(); double ccilong=iCCI(Symbol(),0,longperiod,PRICE_OPEN,0); double ccishort=iCCI(Symbol(),0,shortperiod,PRICE_OPEN,0); double ema1=iMA(Symbol(),0,shortema,0,MODE_EMA,PRICE_OPEN,0); double ema2=iMA(Symbol(),0,longema,0,MODE_EMA,PRICE_OPEN,0); double emas = ema1 - ema2; if (offswitch) { if (ccishort > 0 && ccilong > 0 && downswitch && emas > 0) { OrderSend(Symbol(),OP_BUY,1,Ask,1,Ask - stoploss*Point,Bid + takeprofit*Point,NULL,magic,0,Blue); offswitch=false; onswitch=true; upswitch=true; downswitch=false; upswitch2=true; downswitch2=false; } if (ccishort < 0 && ccilong < 0 && upswitch && emas < 0) { OrderSend(Symbol(),OP_SELL,1,Bid,1,Bid + stoploss*Point, Ask - takeprofit*Point,NULL,magic,0,Blue); offswitch=false; onswitch=true; downswitch=true; upswitch=false; downswitch2=true; upswitch2=false; } } if (onswitch) { int orderstotal=0; int allorders; for(allorders=OrdersTotal();allorders>0;allorders--) { OrderSelect(allorders,SELECT_BY_POS); if (OrderSymbol() == Symbol() && OrderMagicNumber() == magic) orderstotal++; } if (orderstotal == 0) { onswitch=false; offswitch=true; } } //---- return(0); } //+------------------------------------------------------------------+